package portal.cmd.beans;

import portal.common.MyStringUtils;

public class ResourceBean {
	String hostName=null;
	int cpu=100;
	int memU=Integer.MAX_VALUE;
	int memT;
	int core=0;
	public ResourceBean(){
		
	}
	public ResourceBean(String host){
		hostName=host;
	}
	public String getHostName() {
		return hostName;
	}
	public void setHostName(String hostName) {
		this.hostName = hostName;
	}
	public int getCpu() {
		return cpu;
	}
	public void setCpu(int cpu) {
		this.cpu = cpu;
	}
	public void setCpu(String cpu) {
		this.cpu = Integer.valueOf(cpu.substring(0, cpu.indexOf('%')));
	}
	public int getMemU() {
		return memU;
	}
	public void setMemU(int memU) {
		this.memU = memU;
	}
	public int getMemT() {
		return memT;
	}
	public void setMemT(int memT) {
		this.memT = memT;
	}
	public void setMemT(String memT) {
		int cur=0;
		if(memT.contains("G")){
			cur = Integer.valueOf(memT.replace("G", ""))*1024;
		}else if(memT.contains("M")){
			cur = Integer.valueOf(memT.replace("M", ""));
		}
		this.memT = cur;
	}
	public int getCore() {
		return core;
	}
	public void setCore(int core) {
		this.core = core;
	}
	public boolean isAvaliable(int mem,int cpu){
		if(memT-mem<=0)
			return false;
		if((cpu+this.cpu)>=100)
			return false;
		return true;
	}
}
